﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using ZSZ.Core.Entities;

namespace ZSZ.EntityFramework.ModelConfig
{
    class HousePicConfig:EntityTypeConfiguration<HousePicEntity>
    {
        //public HousePicConfig()
        //{
        //    ToTable("T_HousePics");
        //    //HousePicConfig和AdminLogConfig不一样的地方：如果有反向导航属性，则要HousePicConfig的写法
        //    //否则就是AdminLogConfig的写法
        //    HasRequired(p => p.House).WithMany(p=>p.HousePics).HasForeignKey(p => p.HouseId).WillCascadeOnDelete(false);
        //    Property(p => p.ThumbUrl).IsRequired().HasMaxLength(1024);
        //    Property(p => p.Url).IsRequired().HasMaxLength(1024);
        //}

        public override void Map(EntityTypeBuilder<HousePicEntity> builder)
        {
            builder.ToTable("T_HousePic");
            builder.Property(p => p.ThumbUrl).IsRequired().HasMaxLength(1024);
            builder.Property(p => p.Url).IsRequired().HasMaxLength(1024);
            builder.HasOne(e => e.House).WithMany(e => e.HousePics).HasForeignKey(e => e.HouseId)
                .OnDelete(DeleteBehavior.ClientSetNull);
        }
    }
}
